import 'package:flutter/material.dart';
import 'package:ts_app_dart/widget/my_scroll_widget.dart';

class OrderTrackPage extends StatefulWidget {
  const OrderTrackPage({Key key}) : super(key: key);

  @override
  _OrderTrackPageState createState() => _OrderTrackPageState();
}

class _OrderTrackPageState extends State<OrderTrackPage> {
  final List<String> _timeList = [
    '2019/08/30 13:30',
    '2019/08/30 11:30',
    '2019/08/30 9:30',
    '2019/08/30 9:00'
  ];
  final List<String> _titleList = ['订单已完成', '开始配送', '等待配送', '收到新订单'];

  Step _buildStep(int index) {
    final Color primaryColor = Theme.of(context).primaryColor;
    return Step(
      title: Padding(
        padding: const EdgeInsets.only(top: 15.0),
        child: Text(_titleList[index],
            style: index == 0
                ? TextStyle(
                    fontSize: 14.0,
                    color: primaryColor,
                  )
                : Theme.of(context).textTheme.bodyMedium),
      ),
      subtitle: Text(_timeList[index],
          style: index == 0
              ? TextStyle(
                  fontSize: 12.0,
                  color: primaryColor,
                )
              : Theme.of(context).textTheme.titleSmall),
      content: const Text(''),
      isActive: index == 0,
      // TODO(weilu): 这里的状态图标无法修改，暂时使用原生的。应该可以复制Step代码修改一下。
      state: index == 0 ? StepState.complete : StepState.indexed,
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('订单跟踪'),
      ),
      body: MyScrollWidget([
        Padding(
          padding: const EdgeInsets.only(top: 21.0, left: 16.0, right: 16.0),
          child: Row(
            children: <Widget>[
              const Text('订单编号：'),
              // 可选择文本组件（复制）
              Semantics(
                label: '长按复制订单编号',
                child: const SelectableText(
                  '14562364879',
                  maxLines: 1,
                ),
              ),
            ],
          ),
        ),
        Stepper(
          physics: BouncingScrollPhysics(),
          currentStep: 4 - 1,
          controlsBuilder: (_, __) {
            // 操作按钮置空
            return SizedBox.shrink();
          },
          steps: List.generate(4, (i) => _buildStep(i)),
        )
      ]),
    );
  }
}
